﻿/*
* SplashScene.cpp
*
* 启动场景
*
* create date: 2014.4.10
* create by: leo
*
*/

#include "SplashScene.h"

#include "SceneManager.h"
#include "../user/User.h"

USING_NS_CC;
using namespace cocos2d::ui;

CBaseScene* CSplashScene::create()
{
	CSplashScene* scene = new CSplashScene();
	if (NULL != scene && scene->init())
	{
		scene->autorelease();
		return scene;
	}

	return NULL;
}

void CSplashScene::onTouchEnter(CCObject* obj, TouchEventType type)
{
	switch (type)
	{
	case TOUCH_EVENT_BEGAN:
		break;

	case TOUCH_EVENT_ENDED:
		CUser::getInstance().login(this, callfunc_selector(CSplashScene::onLoginSuccess));
		break;
	}
}

CSplashScene::CSplashScene(void)
{}

CSplashScene::~CSplashScene(void)
{}

bool CSplashScene::init(void)
{
	CCSprite* bg = CCSprite::create("HelloWorld.png");
	CENTRE(bg);
	this->addChild(bg);

	TouchGroup* tg = TouchGroup::create();
	this->addChild(tg);

	Button* btn = Button::create();
	btn->setTitleText("Enter");
	btn->loadTextures("CloseNormal.png", "CloseNormal.png", "CloseNormal.png");
	btn->addTouchEventListener(this, toucheventselector(CSplashScene::onTouchEnter));
	CENTRE(btn);
	tg->addWidget(btn);

	return true;
}

void CSplashScene::onLoginSuccess()
{
	CSceneManager::TransferToScene(BATTLE_SCENE);
}
